package com.suxin.test.netty.adv.server;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.extern.slf4j.Slf4j;
import org.example.netty.adv.vo.KryoSerializer;
import org.example.netty.adv.vo.Message;

/**
 * @Author: tang
 * @Description: 业务编码器
 * @Date 2025/1/21 13:56
 */
@Slf4j
public class KryoEncoder extends MessageToByteEncoder<Message> {

    @Override
    protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) throws Exception {
        KryoSerializer.serialize(msg, out);
        ctx.flush();
    }
}
